import Vue from "vue";

//补0
function zero(num) {
  return num < 10 ? "0" + num : num;
}
//   2020-2-2
Vue.filter("timeType", function(time) {
  if (String(time).length !== 13) {
    return time;
  }
  let d = new Date(time);
  let t =
    d.getFullYear() + "-" + zero(d.getMonth() + 1) + "-" + zero(d.getDate());
  return t;
});

// 2020-2-2 12:00:00
Vue.filter("timeType2", function(time) {
  if (String(time).length !== 13) {
    return time;
  }
  let date = new Date(time);
  let year = date.getFullYear();
  let month = zero(date.getMonth() + 1); //月份是从0开始的
  let day = zero(date.getDate());
  let hour = zero(date.getHours());
  let min = zero(date.getMinutes());
  let sec = zero(date.getSeconds());
  let newTime =
    year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
  return newTime;
});
